import App from './App'

import http from '@/request/http.js';
import store from './store';
import * as routerPath from '@/lib/routerPath.js';

import uView from 'uview-ui';
Vue.use(uView);

Vue.mixin({
	computed: {
		"vuex": function() {
			return this.$store.state;
		}
	}
});

const site_url = 'http://192.168.1.108:7676/';
const image_url = 'http://192.168.1.108:7676';
// const site_url = 'http://127.0.0.1:7676/';
// const image_url = 'http://127.0.0.1:7676';
const oss_url = 'https://shengxingche.oss-cn-beijing.aliyuncs.com/';

const resourse_path = site_url + 'static/app/';
Vue.prototype.site_url = site_url;
Vue.prototype.image_url = image_url;
Vue.prototype.oss_url = oss_url;

// #ifdef MP-WEIXIN
import share from '@/common/share.js'
Vue.mixin(share);
// #endif

Vue.prototype.$store = store;
Vue.prototype.areq = http.areq;
Vue.prototype.req = http.sync_req;
Vue.prototype.lb_upload = http.lb_upload;
Vue.prototype.$r = routerPath.p;
Vue.prototype.showMsg = (title, duration = 1500, mask = false, icon = 'none') => {
	//统一提示方便全局修改
	if (Boolean(title) === false) {
		return;
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
};

Vue.prototype.realUrl = (url) => {
	if (url) {
		var xy = url.substr(0, 7).toLowerCase();
		var xys = url.substr(0, 8).toLowerCase();
		if (xy == 'http://' || xys == 'https://') {
			return url;
		} else {
			return image_url + url;
		}
	} else {
		return '/static/addImg.png';
	}
};

Vue.prototype.backTo = function(num = 1) {
	let pages = getCurrentPages();
	let prevPage = pages[pages.length - num - 1]; //上一个页面
	if (prevPage) {
		uni.navigateBack({
			delta: num
		});
	} else {
		uni.reLaunch({
			url: '/pages/index/index'
		})
	}
};

Vue.prototype.get_args = function(scene) {
	let opt = [];
	if (scene != undefined) {
		let scene = decodeURIComponent(scene).split('&')
		for (let i of scene) {
			opt[i.split("=")[0]] = i.split("=")[1];
		}
		return opt;
	} else {
		return [];
	}
};

// 时间转换
Vue.filter('formatTime', function(timestamp) {
	if (!timestamp) {
		// return ''
	}
	var date = new Date(timestamp * 1000);
	var Y = date.getFullYear();
	var M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
	var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
	var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
	var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
	var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
	return Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s
})

Vue.filter('formatTime1', function(timestamp) {
	if (!timestamp) {
		// return ''
	}
	var date = new Date(timestamp * 1000);
	var Y = date.getFullYear();
	var M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
	var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
	var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
	var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
	// var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
	return Y + '-' + M + '-' + D + ' ' + h + ':' + m;
})

Vue.filter('formatDate', function(timestamp) {
	if (!timestamp) {
		// return ''
	}
	var date = new Date(timestamp * 1000);
	var Y = date.getFullYear();
	var M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
	var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();

	return Y + '-' + M + '-' + D;
})

Vue.filter('formatY', function(timestamp) {
	if (!timestamp) {
		// return ''
	}
	var date = new Date(timestamp * 1000);
	var Y = date.getFullYear();
	return Y;
})

Vue.prototype.previewImg = function(item, index) {
	uni.setStorageSync("currentImgIndex", index) // 当前下标
	uni.setStorageSync('imgPreviewPicList', item) // 当前数组
	uni.navigateTo({
		url: '/pages/public/preview' // 要跳转的预览页
	})
};



// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
    ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif